<template>
	<section class="jumbotron">
      <h3 class="jumbotron-heading">Search Github Users</h3>
      <div>
        <input type="text" placeholder="enter the name you search" v-model="value"/>&nbsp;
        <button @click="fetch">Search</button>
      </div>
    </section>
</template>

<script>
import axios from 'axios'
	export default {
		name:'Search',
		data() {
      return {
        value:''
      }
    },
    methods:{
      fetch(){
        //发送请求等待中
        this.$bus.$emit('getusers',{isFrist:false,isLoading:true,errmessage:'',users:[]})
         axios.get(`https://api.github.com/search/users?q=${this.value}`)
         .then(
          response => {
            console.log('请求成功',response.data)
            // 请求发送成功
            this.$bus.$emit('getusers',{isLoading:false,errmessage:'',users:response.data.items})
          },
          error => {
            //请求发送失败
            this.$bus.$emit('getusers',{isLoading:false,errmessage:error.message,users:[]})
          }
         )
      }
      
    }
	}
</script>
